import { SectReader } from './sect-reader';
import type { SectConfig } from '../../data/sect/type';

export class SectManager {
  /** 所有宗门 */
  private sects = new Map<string, SectConfig>();
  /** 当前宗门 */
  private currentSectId: string | null = null;
  /** 宗门贡献度 */
  private currentSectContribution = 0;

  constructor() {
    const configs = SectReader.getConfigs();
    configs.forEach((config) => this.registerSect(config));
  }

  /** 根据 id 获取宗门配置 */
  public getSectById(id: string) {
    return this.sects.get(id) || null;
  }

  /** 设置当前宗门 id */
  public setCurrentSectId(sectId: string | null) {
    this.currentSectId = sectId;
  }

  /** 获取当前宗门 id */
  public getCurrentSectId() {
    return this.currentSectId;
  }

  /** 获取当前宗门 */
  public getCurrentSect() {
    return this.currentSectId;
  }

  /** 获取当前宗门贡献度 */
  public getCurrentSectContribution() {
    return this.currentSectContribution;
  }

  /** 设置当前宗门贡献度 */
  public setCurrentSectContribution(contribution: number) {
    this.currentSectContribution = contribution;
  }

  /** 清空当前宗门贡献度 */
  public clearContribution() {
    this.currentSectContribution = 0;
  }

  /** 注册宗门 */
  public registerSect(sect: SectConfig) {
    this.sects.set(sect.id, sect);
  }

  public getSects() {
    return [...this.sects.values()];
  }
}
